package com.share.rule.factory;

import com.share.common.core.domain.R;
import com.share.rule.api.RemoteFeeRuleService;
import com.share.rule.domain.FeeRule;
import com.share.rule.domain.FeeRuleRequestForm;
import com.share.rule.domain.FeeRuleResponseVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author ZhouShuang
 * @version 17
 * @Title
 * @date 2025/10/20 上午11:31
 */
@Component
@Slf4j
public class RemoteFeeRuleFallbackFactory implements FallbackFactory<RemoteFeeRuleService> {
    @Override
    public RemoteFeeRuleService create(Throwable cause) {
        log.error("规则服务调用失败: {}", cause.getMessage());
        return new RemoteFeeRuleService() {
            @Override
            public R<List<FeeRule>> getFeeRuleList(List<Long> feeRuleIds) {
                return R.fail("获取费用规则列表失败:" + cause.getMessage());
            }

            @Override
            public R<FeeRule> getFeeRule(Long id) {
                return R.fail("获取费用规则详情失败:" + cause.getMessage());
            }

            @Override
            public R<FeeRuleResponseVo> calculateOrderFee(FeeRuleRequestForm requestForm) {
                return R.fail("计算订单费用失败:" + cause.getMessage());
            }
        };
    }
}
